package cn.b.sky.mes.cm.model;

import cn.b.sky.common.model.ImeCommon;

/**
 * 工作时段
 * @author zhaoxin01
 * @version 1.0 
 * history 
 * Symbol Date  Person  Note
 * [1]  2016/01/08 zhaoxin01  Generated.
 */
public class WorkDayPeriod extends ImeCommon implements Comparable<WorkDayPeriod> {

  /**
   * 工厂编号:nvarchar2(20) <Primary Key>
   */
  private String siteCode;

  /**
   * 日类型编号:nvarchar2(20) <Primary Key>
   */
  private String dayTypeCode;

  /**
   * 序号:number(10) <Primary Key>
   */
  private Long ordinal;

  /**
   * 开始时间:date(0)
   */
  private String startTime;

  /**
   * 结束时间:date(0)
   */
  private String endTime;

  /**
   * 跨天标志:number(1)
   */
  private int spanDaysFlag;

  /**
   * 下一天标志:number(1)
   */
  private int nextDayFlag;

  @Override
  public String getSiteCode() {
    return siteCode;
  }

  @Override
  public void setSiteCode(String siteCode) {
    this.siteCode = siteCode;
  }

  public String getDayTypeCode() {
    return dayTypeCode;
  }

  public void setDayTypeCode(String dayTypeCode) {
    this.dayTypeCode = dayTypeCode;
  }

  public Long getOrdinal() {
    return ordinal;
  }

  public void setOrdinal(Long ordinal) {
    this.ordinal = ordinal;
  }

  public String getStartTime() {
    return startTime;
  }

  public void setStartTime(String startTime) {
    this.startTime = startTime;
  }

  public String getEndTime() {
    return endTime;
  }

  public void setEndTime(String endTime) {
    this.endTime = endTime;
  }

  public int getSpanDaysFlag() {
    return spanDaysFlag;
  }

  public void setSpanDaysFlag(int spanDaysFlag) {
    this.spanDaysFlag = spanDaysFlag;
  }

  public int getNextDayFlag() {
    return nextDayFlag;
  }

  public void setNextDayFlag(int nextDayFlag) {
    this.nextDayFlag = nextDayFlag;
  }

  @Override
  public int compareTo(WorkDayPeriod o) {
    if (spanDaysFlag == 0 && nextDayFlag == 0) {
      return compareForNotNextDay(o);
    } else if (spanDaysFlag == 1) {
      return compareForNotNextDay(o);
    } else {
      if (o.getSpanDaysFlag() == 0 && o.getNextDayFlag() == 0) {
        return 1;
      } else if (o.getSpanDaysFlag() == 1) {
        return 1;
      } else {
        return startTime.compareTo(o.getStartTime());
      }
    }
  }

  private int compareForNotNextDay(WorkDayPeriod o) {
    if (o.getSpanDaysFlag() == 0 && o.getNextDayFlag() == 0) {
      return startTime.compareTo(o.getStartTime());
    } else if (o.getSpanDaysFlag() == 1) {
      return startTime.compareTo(o.getStartTime());
    } else {
      return -1;
    }
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((dayTypeCode == null) ? 0 : dayTypeCode.hashCode());
    result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
    result = prime * result + nextDayFlag;
    result = prime * result + ((ordinal == null) ? 0 : ordinal.hashCode());
    result = prime * result + ((siteCode == null) ? 0 : siteCode.hashCode());
    result = prime * result + spanDaysFlag;
    result = prime * result + ((startTime == null) ? 0 : startTime.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null) {
      return false;
    }
    if (getClass() != obj.getClass()) {
      return false;
    }
    WorkDayPeriod other = (WorkDayPeriod) obj;
    if (dayTypeCode == null) {
      if (other.dayTypeCode != null) {
        return false;
      }
    } else if (!dayTypeCode.equals(other.dayTypeCode)) {
      return false;
    }
    if (endTime == null) {
      if (other.endTime != null) {
        return false;
      }
    } else if (!endTime.equals(other.endTime)) {
      return false;
    }
    if (nextDayFlag != other.nextDayFlag) {
      return false;
    }
    if (ordinal == null) {
      if (other.ordinal != null) {
        return false;
      }
    } else if (!ordinal.equals(other.ordinal)) {
      return false;
    }
    if (siteCode == null) {
      if (other.siteCode != null) {
        return false;
      }
    } else if (!siteCode.equals(other.siteCode)) {
      return false;
    }
    if (spanDaysFlag != other.spanDaysFlag) {
      return false;
    }
    if (startTime == null) {
      if (other.startTime != null) {
        return false;
      }
    } else if (!startTime.equals(other.startTime)) {
      return false;
    }
    return true;
  }

}
